/* dsw.t     DISTRIBUTION ORDER LINE WRITE TRIGGER                    */
/*Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                 */
/*All rights reserved worldwide.  This is an unpublished work.        */
/*V8:ConvertMode=NoConvert*/
/*********************************************************************/
/*  Program :dsw.t                                                   */
/*  Author  :Ben Holmes                                              */
/*  Date    :01/29/96                                                */
/*  !Description : ds_det WRITE trigger program                      */
/*          : In order to enhance this trigger to support additional */
/*          : interfaces, add a DO-END block similar to the one      */
/*          : used for the Warehousing Interface to (1) check for the*/
/*          : need to continue processing; (2) move the relevant     */
/*          : fields to an appropriate work area; and (3) call       */
/*          : one or more subprograms to continue processing.        */
/*          : This .t program should remain short, relying on        */
/*          : subprograms to perform most of the work.               */
/*********************************************************************/
/*                             MODIFY LOG                            */
/*********************************************************************/
/*Revision 8.5          Last Modified:  01/29/96 BY: BHolmes *J0FY*  */
/*Revision 8.5          Last Modified:  07/19/96 BY: fwy     *J0MB*  */
/*Revision 8.5          Last Modified:  07/27/96 BY: fwy     *J12B*  */
/*Revision 8.5          Last Modified:  01/07/97 BY: jpm     *J1DM*  */
/*Revision 9.1          Last Modified:  08/14/00 BY: *N0KW* Jacolyn Neder */
/*                                                                   */
/*                                                                   */
/*********************************************************************/

TRIGGER PROCEDURE FOR WRITE OF DS_DET OLD BUFFER OLD_DS_DET.

/*J12B  if not can-find(first whl_mstr where whl_mstr.whl_act no-lock) */
/*J12B  then leave. */

    {mfdeclre.i }
    define new shared work-table wf_old_ds_det like ds_det.
    define new shared variable w-recid as recid.
    define variable w-file as character format "x(24)".
    define new shared variable w-site-loc-id like whl_mstr.whl_src_dest_id.


    /* Warehousing Interface processing */

    WI:
    do:

    /* If there is no active external warehouse that is flagged to
    receive distribution order export transactions, then do not process */
/*J12B*/    if not can-find(first whl_mstr no-lock
/*J12B*/        where whl_mstr.whl_act and whl_mstr.whl_do_exp)
/*J12B*/    then leave WI.

    /* If no pertinent fields have been changed, then do not process */
/*J12B*/    if   (old_ds_det.ds_nbr       = ds_det.ds_nbr
/*J12B*/      and old_ds_det.ds_req_nbr   = ds_det.ds_req_nbr
/*J12B*/      and old_ds_det.ds_part      = ds_det.ds_part
/*J12B*/      and old_ds_det.ds_rev       = ds_det.ds_rev
/*J12B*/      and old_ds_det.ds_shipsite  = ds_det.ds_shipsite
/*J12B*/      and old_ds_det.ds_site      = ds_det.ds_site
/*J12B*/      and old_ds_det.ds_loc       = ds_det.ds_loc
/*J12B*/      and old_ds_det.ds_qty_conf  = ds_det.ds_qty_conf
/*J12B*/      and old_ds_det.ds_qty_pick  = ds_det.ds_qty_pick
/*J12B*/      and old_ds_det.ds_trans_id  = ds_det.ds_trans_id
/*J12B*/      and old_ds_det.ds_rmks      = ds_det.ds_rmks
/*J12B*/      and old_ds_det.ds_user1     = ds_det.ds_user1
/*J12B*/      and old_ds_det.ds_user2     = ds_det.ds_user2
/*J12B*/      and old_ds_det.ds_cmtindx   = ds_det.ds_cmtindx)
/*J12B*/    then leave WI.

    /* Move old ds_det values to work table for subsequent processing */
        assign w-recid = recid(ds_det).
        create wf_old_ds_det.
        if recid(wf_old_ds_det)= -1 then .
        assign
            wf_old_ds_det.ds_nbr       = old_ds_det.ds_nbr
            wf_old_ds_det.ds_req_nbr   = old_ds_det.ds_req_nbr
            wf_old_ds_det.ds_part      = old_ds_det.ds_part
            wf_old_ds_det.ds_rev       = old_ds_det.ds_rev
            wf_old_ds_det.ds_shipsite  = old_ds_det.ds_shipsite
            wf_old_ds_det.ds_site      = old_ds_det.ds_site
            wf_old_ds_det.ds_loc       = old_ds_det.ds_loc
            wf_old_ds_det.ds_qty_conf  = old_ds_det.ds_qty_conf
            wf_old_ds_det.ds_qty_pick  = old_ds_det.ds_qty_pick
            wf_old_ds_det.ds_trans_id  = old_ds_det.ds_trans_id
            wf_old_ds_det.ds_rmks      = old_ds_det.ds_rmks
            wf_old_ds_det.ds_user1     = old_ds_det.ds_user1
            wf_old_ds_det.ds_user2     = old_ds_det.ds_user2
/*J12B*/        wf_old_ds_det.ds_cmtindx   = old_ds_det.ds_cmtindx
        .

    /* Call appropriate subprograms to create export transactions */

    /* If the quantity confirmed is being changed from - to +,
    then create a delete transaction first */
        if wf_old_ds_det.ds_qty_conf lt 0
          and     ds_det.ds_qty_conf ge 0
        then do:
            w-file = "widsd.p".
/*J1DM*/ /*     {gprun.i ""widsd.p""} */
/*J1DM*/        {gprunmo.i &module="WI"
                           &program="widsd.p"}
        end.

    /* If the line being added/changed has a negative quantity confirmed,
    then create a delete transaction if the distribution order has
    been nulled; otherwise create an add/change transaction */
        if ds_det.ds_qty_conf lt 0
        then do:
/*J0MB*/        if ds_det.ds_nbr = ""
/*J0MB*/        then do:
/*J0MB*/            w-file = "widsd.p".
/*J1DM*/ /*J0MB     {gprun.i ""widsd.p""} */
/*J1DM*/            {gprunmo.i &module="WI"
                               &program="widsd.p"}
/*J0MB*/        end.
/*J0MB*/        else do:
                w-file = "widsw2.p".
/*J1DM*/ /*         {gprun.i ""widsw2.p""} */
/*J1DM*/        {gprunmo.i &module="WI"
                           &program="widsw2.p"}
/*J0MB*/        end.
/*J0MB          leave. */
        end.

    /* If the line being added/changed has a positive quantity confirmed,
    then create an add/change transaction if there is a picked quantity */
        if ds_det.ds_qty_conf ge 0
        then do:
            w-file = "widsw.p".
/*J1DM*/ /*     {gprun.i ""widsw.p""} */
/*J1DM*/        {gprunmo.i &module="WI"
                           &program="widsw.p"}
        end.

/*J12B*/end. /* WI */
